#告警
from selenium.webdriver.common.by import By
from base.base import Base


class PageAlarm(Base):
    #页面跳转
    pagetitle_locator = (By.XPATH,'(//li[@role="menuitem"])[5]')
    #站点选择
    input_site_locator = (By.XPATH,'(//div[@class="ant-select-selector"]//input)[1]')
    #设备选择框
    input_device_locator = (By.XPATH,'(//div[@class="ant-select-selector"]//input)[2]')
    #下拉框第一个元素
    seleted_locator = (By.XPATH,'(//div[@class="ant-cascader-menus"]//li)[1]')
    #选择设备
    device_locator = (By.XPATH,'//div[@label="xq测试-通用测温"]')
    #查询按钮
    select_btu_locator = (By.XPATH,'(//button[contains(@class,"ant-btn")])[1]')
    #告警列表
    alarm_list_locator = (By.XPATH,'//tbody//*[contains(@class,"ant-table-cell")]')
    #第一个查看按钮
    check_locator = (By.XPATH,'(//a[text()="查看"])[1]')
    #页面详情
    details_locator = (By.CLASS_NAME,'ant-descriptions-item-content')
    #详情页面关闭按钮
    detail_closebt_locator = (By.XPATH,'//div[@class="ant-modal-footer"]/button')




    def pagejump(self):
        self.click(self.pagetitle_locator)
    #输入站点
    def input_site(self,name):
        self.clear(self.input_site_locator)
        self.input(self.input_site_locator,name)
        self.click(self.seleted_locator)
    #输入设备名称
    def input_device(self,name):
        self.clear(self.input_device_locator)
        self.input(self.input_device_locator,name)
        self.click(self.device_locator)
    #点击查询
    def click_select_btn(self):
        self.click(self.select_btu_locator)
    #获取告警列表
    def get_alarmlist(self):
        values =[]
        for index,elm in enumerate(self.finds(self.alarm_list_locator)):
            if index%9 != 0 and index%9 != 8:
                values.append(elm.text)
        return values
    #点击查看按钮
    def click_checkbtn(self):
        self.click(self.check_locator)
    #获取详情信息
    def get_details(self):
        values = []
        elms = self.finds(self.details_locator)
        for elm in elms:
            values.append(elm.text)
        return values
    #关闭详情页面
    def close_details(self):
        self.click(self.detail_closebt_locator)
